package com.szpx.controller;


import com.szpx.entity.Film;
import com.szpx.entity.lishihui.Cinema;
import com.szpx.service.CinemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class CinemaController {
    @Autowired
    private CinemaService cinemaService;

    @GetMapping("/cinema")
    public String allcinema(Model model){
        List<Cinema> cinemas = cinemaService.allCinema();
        model.addAttribute("cinemas",cinemas );
        return "cinemahtml/cinema.html";
    }
    @GetMapping("/toCinema")
    public  String toAdd(){
        return "cinemahtml/add.html";
    }

    @PostMapping("/addCinema")
    public String addCinema(Cinema cinema){
        cinemaService.addCinema(cinema);

        return "redirect:/cinema";
    }


    @GetMapping("/delCinema/{id}")
    public String deleteCinema(@PathVariable(value = "id")Integer id){
        System.out.println("sdasdasd"+id);
        cinemaService.deleteCinema(id);
        System.out.println("123");
        return "redirect:/cinema";
    }





}
